#define __KERNEL__
#define MODULE

#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/mm.h>

unsigned long va;

static int vmmcall(int eax, int ebx, int ecx, int edx, int edi, int esi)
{
	int x = 10;
	
	__asm__ __volatile__ (
		".byte 0x0F,0x01,0xC1"
		:"=a"(x)
		:"a"(eax),
		"b"(ebx), "c"(ecx), "d"(edx), "D"(edi), "S"(esi) );

	return eax;
}


int init_module(void)
{
	int ret;
	printk(KERN_INFO "Load vmmcall module \n");

	va = __get_free_page(GFP_KERNEL);
	//va = kmalloc(256,GFP_KERNEL);
	//memset(va, 0, 256);
	strcpy(va, "tracing");
	printk(KERN_INFO "BUF %s, VIRTUAL aDDRESS = %x \n",va, (unsigned int) va);
	//strcpy((char *)va, "K");
	//strcpy((char *)va, "V");
	//strcpy((char *)va, "M\0");
	//strcpy(va, "link\n");
	ret = vmmcall(17,10, va,5,7,9);

	printk(KERN_INFO "Ret val %d rcx: %ld\n", ret, va);

	return ret;
}


void cleanup_module(void)
{
	free_page(va);

	printk(KERN_INFO "Unload vmmcall module \n");
}
